package com.toune.dltools.http

object DLHttpConfig {
    /**
     * 如果字段名和默认的一样可以直接使用只含有data的Bean作为模板类，不会用的建议不要设置
     */
    var useDefaultStr = true
    var tokenErrorListener: TokenErrorListener? = null

    fun setSuccessCode(successCode: Int): DLHttpConfig {
        IBaseCallBack.SUCCESS_CODE = successCode
        return this
    }

    fun setErrorCode(errorCode: Int): DLHttpConfig {
        IBaseCallBack.ERROR_CODE = errorCode
        return this
    }

    fun setTokenErrorCode(errorCode: Int): DLHttpConfig {
        IBaseCallBack.TOKEN_ERROR_CODE = errorCode
        return this
    }

    fun setTokenErrorCode(errorCode: Int, tokenErrorListener: TokenErrorListener): DLHttpConfig {
        this.tokenErrorListener = tokenErrorListener
        IBaseCallBack.TOKEN_ERROR_CODE = errorCode
        return this
    }

    fun setHeader(map: Map<String, Any>) {
        IBaseCallBack.headerMap.clear()
        IBaseCallBack.headerMap.putAll(map)
    }

    fun setDataStr(code: String, msg: String, data: String): DLHttpConfig {
        useDefaultStr = false
        IBaseCallBack.codeStr = code
        IBaseCallBack.msgStr = msg
        IBaseCallBack.dataStr = data
        return this
    }

    interface TokenErrorListener {
        fun onTokenError()
    }
}